var invite_param="",invite_array=new Array("","","");
var alert_prefixe="",num_window=0,prompt_text="";

function add_alert(file,noeud,invites)
{alert_prefixe=noeud;invite_param=invites;
node=svgdoc.getElementById(noeud);
getURL (file, window_active);
};

function add_confirm(file,noeud,invites,num)
{alert_prefixe=noeud;invite_param=invites;num_window=num;
node=svgdoc.getElementById(noeud);
getURL (file, window_active);
};

function add_prompt(file,noeud,invites,num)
{
alert_prefixe=noeud;invite_param=invites;num_window=num;prompt_text="";
node=svgdoc.getElementById(noeud);
getURL (file, window_active);
};

function window_active( data ) {
if (data.success) {
var doc_frag = parseXML ( data.content, svgdoc);
childs=doc_frag.getChildNodes();
nombre=childs.getLength();
for (i=0;i<nombre;i++)
{child=childs.item(i);
node.appendChild (child)};
textes_init()
} else {
alert ("Error reading file");
}}

function remove_window(noeud)
{ou=svgdoc.getElementById(noeud);
childs=ou.getChildNodes();
nombre=childs.getLength();
for (i=nombre-1;i>=0;i--)
{child=childs.item(i);
ou.removeChild (child)}
}

function textes_init()
{
analyse_chaine();
ecris_chaine();
}

function analyse_chaine()
{invite_array=["","",""];
invite_array=invite_param.split("\n");
}

function ecris_chaine()
{for (i=0;i<3;i++)
{objet = svgdoc.getElementById('invite'+i.toString());
child=objet.getFirstChild();
child.setData(invite_array[i])
}
}

function prompt_tape(evt)
{key = evt.getCharCode();
if ((key!=13)&&(key!=27))
{if ((key==8)&&(prompt_text!="")) {prompt_text=prompt_text.substring(0,prompt_text.length-1)}
else
{lettre = String.fromCharCode(key);prompt_text=prompt_text+lettre}; 
objet=svgdoc.getElementById("prompt_result");child=objet.getFirstChild();child.setData(prompt_text)}
else
{if (key==13) {sortie=true} else {sortie=false};
close_prompt(sortie)}}

function alert_tape(evt)
{key = evt.getCharCode();
if (key==13)
{close_alert(true)}}

function confirm_tape(evt)
{key = evt.getCharCode();
if (key==13) {close_confirm(true)};
if (key==27) {close_confirm(false)};
}

function close_alert(result)
{
remove_window(alert_prefixe);
}

function close_confirm(result)
{
remove_window(alert_prefixe);
eval(alert_prefixe+"_use_confirm(result,num_window)");
}

function close_prompt(result)
{
remove_window(alert_prefixe);
eval(alert_prefixe+"_use_prompt(result,prompt_text,num_window)");
}
